home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / tchk21ex.zip / DEMOADV.C next >
C/C++ Source or Header  |  1989-06-06  |  5KB  |  127 lines

  1. /* TCHK 2.1 - Howard Kapustein's Turbo C library        6-6-89      */
  2. /* Copyright (C) 1988,1989 Howard Kapustein.  All rights reserved.  */
  3.  
  4. /* demoadv.c  -  used for testing TCHK advanced date conversions */
  5.  
  6. #include <howard.h>
  7. #include <datehk.h>
  8. #include <dateadv.h>
  9.  
  10. #include <stdio.h>
  11. #include <dos.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14.  
  15. void main(void);
  16.  
  17. void main(void)
  18. {
  19.     extern int _argc;
  20.     extern char **_argv;
  21.     char buff[80], temp[80], temp2[80];
  22.     double dbl, dbl2;
  23.     struct date today, d, d2;
  24.     struct ddate dd, dd2;
  25.     int stype, dtype;
  26.  
  27.     if (_argc<3) {
  28.         printf("DemoAdv is a demonstration program of the advanced date conversions of TCHK.\n\n");
  29.         printf("Usage:  demoadv stype dtype\n\n");
  30.         printf("    demoadv will convert today's date from stype format\n");
  31.         printf("    to dtype format. See TCHK.DOC for more details\n");
  32.         exit(1);
  33.     }
  34.  
  35.     stype = atoi(_argv[1]);
  36.     dtype = atoi(_argv[2]);
  37.     if (stype<1 || stype>43 || dtype<1 || dtype>43) {
  38.         printf("Invalid format (must be 1-43)\n");
  39.         exit(2);
  40.     }
  41.  
  42. /*  for this demo, I get today's date, convert it to format 1 (MM-DD-YY)
  43.     via a sprintf() and then convert it to format stype for the test of
  44.     date_convert(s,d,stype,dtype).                                      */
  45.  
  46.     getdate(&today);
  47.     sprintf(buff,"%2d-%2d-%2d",today.da_mon,today.da_day,today.da_year-1900);
  48.     printf("Today's date: %s     Stype %d:  ",buff,stype);
  49.     switch (stype) {
  50.         case 4:
  51.         case 5:
  52.         case 6:
  53.         case 7:
  54.         case 8:  { date_convert(buff,&dbl,1,stype);
  55.                    printf("%lf",dbl);
  56.                    switch (dtype) {
  57.                        case 4:
  58.                        case 5:
  59.                        case 6:
  60.                        case 7:
  61.                        case 8:  { date_convert(&dbl,&dbl2,1,dtype);  break; }
  62.                        case 9:  { date_convert(&dbl,&d2,1,dtype);    break; }
  63.                        case 10: { date_convert(&dbl,&dd2,1,dtype);   break; }
  64.                        default: { date_convert(&dbl,temp2,1,dtype); break; }
  65.                    }
  66.                    break;
  67.                  }
  68.         case 9:  { date_convert(buff,&d,1,stype);
  69.                    printf("%d %d %d",d.da_day,d.da_mon,d.da_year);
  70.                    switch (dtype) {
  71.                        case 4:
  72.                        case 5:
  73.                        case 6:
  74.                        case 7:
  75.                        case 8:  { date_convert(&d,&dbl2,1,dtype);  break; }
  76.                        case 9:  { date_convert(&d,&d2,1,dtype);    break; }
  77.                        case 10: { date_convert(&d,&dd2,1,dtype);   break; }
  78.                        default: { date_convert(&d,temp2,1,dtype); break; }
  79.                    }
  80.                    break;
  81.                  }
  82.         case 10: { date_convert(buff,&dd,1,stype);
  83.                    printf("%d %d %d",dd.dday,dd.dmon,dd.dyear);
  84.                    switch (dtype) {
  85.                        case 4:
  86.                        case 5:
  87.                        case 6:
  88.                        case 7:
  89.                        case 8:  { date_convert(&dd,&dbl2,1,dtype);  break; }
  90.                        case 9:  { date_convert(&dd,&d2,1,dtype);    break; }
  91.                        case 10: { date_convert(&dd,&dd2,1,dtype);   break; }
  92.                        default: { date_convert(&dd,temp2,1,dtype); break; }
  93.                    }
  94.                    break;
  95.                  }
  96.         default: { date_convert(buff,temp,1,stype);
  97.                    printf("%s",temp);
  98.                    switch (dtype) {
  99.                        case 4:
  100.                        case 5:
  101.                        case 6:
  102.                        case 7:
  103.                        case 8:  { date_convert(temp,&dbl2,1,dtype);  break; }
  104.                        case 9:  { date_convert(temp,&d2,1,dtype);    break; }
  105.                        case 10: { date_convert(temp,&dd2,1,dtype);   break; }
  106.                        default: { date_convert(temp,temp2,1,dtype); break; }
  107.                    }
  108.                    break;
  109.                  }
  110.     }
  111.     printf("   ->   Dtype %d:  ",dtype);
  112.     switch (dtype) {
  113.         case 4:
  114.         case 5:
  115.         case 6:
  116.         case 7:
  117.         case 8:  { printf("%lf",dbl2);  break; }
  118.         case 9:  { printf("%d %d %d",d2.da_day,d2.da_mon,d2.da_year);  break; }
  119.         case 10: { printf("%d %d %d",dd2.dday,dd2.dmon,dd2.dyear);  break; }
  120.         default: { printf("%s",temp2);  break; }
  121.     }
  122.     printf("\n");
  123.  
  124. /* quit */
  125.     exit(0);
  126. }
  127.